<?php
/**
 * 数据库表类 adm_user
 * ============================================================================
 * * 版权所有 度拉拉 * *
 * 网站地址: http://www.dlltrip.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author By: 倪宗锋
 * PhpStorm LoginController.php
 * Create By 2017/06/13 14:40 $
 */

namespace common\models;

use yii\db\ActiveRecord;
use yii\db\Exception;

/**
 * 数据库表类 adm_user.
 * @property integer $uid
 * @property string $u_name
 * @property string $pwd
 * @property string $phone
 * @property string $create_time
 * @property integer $status
 * @property string $last_login
 */
class AdmUser extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'adm_user';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['create_time'], 'safe'],
            [['status'], 'integer'],
            [['u_name'], 'string', 'max' => 100],
            [['pwd'], 'string', 'max' => 255],
            [['phone'], 'string', 'max' => 22],
            [['last_login'], 'string', 'max' => 20],
            [['u_name'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'uid' => 'Uid',
            'u_name' => 'U Name',
            'pwd' => 'Pwd',
            'phone' => 'Phone',
            'create_time' => 'Create Time',
            'status' => 'Status',
            'last_login' => 'Last Login',
        ];
    }

    /**
     * Des:返回管理员的用户信息
     * Name: getUserInfo
     * @param $uid
     * @return array
     * @author 倪宗锋
     */
    public function getUserInfo($uid)
    {
        try {
            $result = self::find()
                ->where(['=', 'uid', $uid])
                ->asArray()
                ->one();
        } catch (Exception $e) {
            $result = [];
        }
        return $result;
    }

    /**
     * Des:根据用户名获取用户信息
     * Name: getUserInfoByName
     * @param $u_name
     * @return array
     * @author 倪宗锋
     */
    public function getUserInfoByName($u_name) {
        try {
            $result = self::find()
                ->where(['=', 'u_name', $u_name])
                ->asArray()
                ->one();
        } catch (Exception $e) {
            $result = [];
        }
        return $result;
    }
}
